package com.mikgonz.farkle.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;

import com.mikgonz.farkle.R;
import com.mikgonz.farkle.Util;
import com.xtify.android.sdk.PersistentLocationManager;

public class Main extends Activity {
	//private AdView adView;
	private PersistentLocationManager pLM;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		pLM = new PersistentLocationManager(this);
		
		Thread xtifyThread = new Thread(new Runnable() {
			@Override
			public void run() {
				pLM.setGpsUsage(false);
				pLM.setLocationTracking(false);
				boolean deliverNotifications = pLM
						.isDeliveringNotifications();
				if (deliverNotifications) {
					pLM.startService();
				}
			}
		});
		xtifyThread.start();
		
		if(pLM.getUserKey() != null){
			Log.w(getClass().getName(), "User Key: " + pLM.getUserKey());
			
			 SharedPreferences.Editor editor = PreferenceManager
				.getDefaultSharedPreferences(this).edit();
			 
			 editor.putString(Util.PREF_XTIFYKEY, pLM.getUserKey());
			 editor.commit();
		}

	}

	public void onStart(View v) {
		startActivity(new Intent(Main.this, PlayerSetup.class));
	}

	public void onOptions(View v) {

		startActivity(new Intent(Main.this, Options.class));
	}

	public void onExit(View v) {
		finish();
	}

	public void onOnline(View v) {
		startActivity(new Intent(Main.this,OnlineActivity.class));
	}
	
	public void onAccounts(View v){
		startActivity(new Intent(Main.this,FarkleGameActivity.class));
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

}